const app = getApp();
const network = require("../../utils/network.js");
const util = require("../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: []
    },

    onShow() {
        this.queryRights()
    },

    queryRights() {
        const _this = this
        util.showLoading('加载中')
        network.GET({
            uri: app.api.queryRights,
            success(res) {
                _this.setData({
                    list: res.data
                })
                _this.storeBtnRights(res.data);
            },
            complete() {
                util.hideLoading()
            }
        })
    },

    // 功能（按钮）权限存储
    storeBtnRights(rights) {
        const getArr = function (list, arr) {
            (list || []).forEach(item => {
                if (item.type > 2) arr.push(item.code);
                if ((item.children || []).length > 0) getArr(item.children, arr);
            });
        };
        let btnRights = [];
        getArr(rights, btnRights);
        //console.log('btnRights', btnRights);
        wx.setStorageSync('btnRights', btnRights || []);
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
    }
})
